﻿<!DOCTYPE html>
<html>
<!-- 工厂运营类HSE合规类证书库-编辑 -->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

</head>

<body>
    <div id="app" class="popupW50" v-cloak>
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="Name">
                            <el-input type="text" v-model="Form.name" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{HSEComplianceCertificateLibraryforFactoryOperations.Name+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="Form.name.length<=0">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>

                        </el-form-item>
                    </div>
                </el-col>


                <el-col :span="11" offset="2">
                    <el-form-item>
                        <div class="elst-select-mini" style="margin-left: -100px">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{HSEComplianceCertificateLibraryforFactoryOperations.Effectivedate+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.effectivedate" type="date" size="mini"
                                                format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择时间">
                                </el-date-picker>
                            </el-input>
                            <span class="iputLineMust" v-if="Form.effectivedate.length<=0">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </div>
                    </el-form-item>
                </el-col>
                <!--附件-->
                <el-col :xs="20" :sm="6" :md="6" :lg="12" :xl="4">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.attachmentName" autocomplete="off" size="mini" disabled="true">
                                <template slot="prepend">
                                    {{Coursewaremanagement.Courseware+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <!--附件上传按钮-->
                <el-col :xs="4" :sm="6" :md="6" :lg="12" :xl="4">
                    <el-upload name="files" class="fl" ref="Attachmentupload" action="/api/File/UploadFile"
                               :before-upload="beforeUpload" :on-success="successUpLoad" :auto-upload="true"
                               :show-file-list="false">
                        <!--:on-preview="handlePreview" :on-remove="handleRemove" :before-upload="fileAttachmentUploadbeforeupload"@click="btnAttachmentUpload"-->
                        <el-button type="primary">导入</el-button>
                    </el-upload>
                </el-col>
                <!--<el-col :span="20">
        <div class="elst-select-mini">
            <el-form-item>
                <el-input disabled type="text" v-model="Form.Courseware" autocomplete="off" size="mini"
                    readonly>
                    <template slot="prepend">
                        {{Coursewaremanagement.Courseware+mark.m}}
                    </template>
                </el-input>
            </el-form-item>
        </div>
    </el-col>
    <el-col :span="4">
        <el-upload ref="Attachmentupload" action="/api/File/UpdateFile" multiple="true"
            :on-preview="handlePreview" :on-remove="handleRemove"
            :before-upload="CoursewareUploadbeforeupload" :auto-upload="true" :limit="1"
            :show-file-list="false">
            <el-button class="ml10" type="primary" size="mini" @click="btnAttachmentUpload">
                {{col.btnImportcourseware}}
            </el-button>
        </el-upload>
    </el-col>-->
            </el-row>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>-->
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
    </div>
    <script type="text/javascript">
        var uploadText = "请选择上传文件";
        var app = new Vue({
            el: '#app',
            data: {
                value1: '',
                radio: '1',
                // picked : '1',
                //父业传参
                id: '',
                //获取下拉菜单frequency
                frequency: [],
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    name: '',
                    effectivedate: '',
                    attachmentId: '',
                    attachmentName: uploadText,

                },
                //表单验证
                rules: {
                    name: [
                        verification.NotNull,
                    ],
                    effectivedate: [
                        verification.NotNull,
                    ],
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                handleRemove: function (file) {
                    console.log(file);
                },
                handlePreview: function (file) {
                    console.log(file.name);
                    window.open(file.url)
                },
                ////上传附件文件的校验
                //CoursewareUploadbeforeupload: function (file) {
                //    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                //    //将附件名赋值到label上
                //    this.Form.Courseware = file.name;
                //    const extension = testmsg === 'doc'
                //    const extension2 = testmsg === 'pdf'
                //    const isLt10M = file.size / 1024 / 1024 < 10
                //    if (!extension && !extension2) {
                //        this.$message({
                //            message: '上传文件只能是 doc、pdf格式!',
                //            type: 'warning'
                //        });
                //    }
                //    if (!isLt10M) {
                //        this.$message({
                //            message: '上传文件大小不能超过 10MB!',
                //            type: 'warning'
                //        });
                //    }
                //    if (extension || extension2 && isLt10M)
                //        submitUpload(this, 'upload')
                //    return extension || extension2 && isLt10M
                //},
                //btnAttachmentUpload: function () {
                //    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                //    if (this.fileAttachmentUpload != uploadText) {
                //        this.$refs.Attachmentupload.clearFiles();
                //        this.fileAttachmentUpload = file.name;
                //    }
                //    else {

                //    }
                //    this.$refs.Attachmentupload.submit();
                //},

                //提交数据
                //上传附件文件的校验
                beforeUpload: function (file) {
                    const isJPG = file.type === 'application/pdf';
                    const isLt2M = file.size / 1024 / 1024 < 20;
                    if (!isJPG) {
                        this.$message.error('仅可上传 pdf 格式!');
                    }
                    if (!isLt2M) {
                        this.$message.error('上传 pdf 大小不能超过 20MB!');
                    }
                    return isJPG && isLt2M; //(isJPG || isPNG) && 
                },
                //上传成功后执行
                successUpLoad: function (res, file) {
                    var data = res.data;//成功后的业务数据
                    var fileModel = data[0];//第一个文件对象
                    //var d = new Date();
                    this.Form.attachmentId = fileModel.id;
                    this.Form.attachmentName = file.name;
                    //this.Form.cbs_list.cbS_ListAttachments.push({
                    //    attachment: fileModel.id,
                    //    path: downLoadPath(fileModel.id),
                    //    name: file.name,
                    //    cbS_ListId: this.id,
                    //    uploadTime: new Date(d.setHours(d.getHours() + 8)).toJSON().substr(0, 19).replace('T', ' '),
                    //    uploadUser: this.Form.sysUser.id,
                    //    sysUser: {
                    //        sysUserInfor: { name: this.Form.sysUser.name, }
                    //    }
                    //});
                },
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            if (mythis.Form.attachmentId == undefined || mythis.Form.attachmentId == null || mythis.Form.attachmentId == '') {
                                alert('请上传pdf');
                                return false;
                            }
                            onSubmitForm(this, '/api/ZB_HSECertificate/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/ZB_HSECertificate/get?id=' + this.id);
                    //this.Form.frequency = this.Form.frequency + "";
                },
            },
            mounted: function () {

                this.id = getUrlParam("id");
                this.getData();
                ////获取下拉菜单内容
                //this.frequency = getDicData('56');
                //初始化数据
                // this.GetPageData(1);
                //列表高度自适应
                tablehigh(this);

            },

        });
    </script>
</body>

</html>